package MULE.Model.Panel;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;

import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;

import MULE.Model.Game;
import MULE.Model.Player;
import MULE.Model.Resource;
import MULE.Model.Logic.MuleDriver;

/**
 * Score panel that shows game data for one player.
 * 
 * @author jstep
 */
public class PlayerScorePanel extends JPanel {

	private JLabel nameLabel, scoreLabel, moneyLabel, foodLabel, energyLabel,
			muleLabel;

	/**
	 * Creates a new score panel that shows data for one player.
	 */
	public PlayerScorePanel() {
		// Initialize panel.
		// Make panel wide enough to have one panel per player + 1 extra for
		// menu panel.
		int panelWidth = MuleDriver.WINDOW_WIDTH / (Game.MAX_NUM_PLAYERS + 1);
		Dimension panelDim = new Dimension(panelWidth, FooterPanel.PANEL_HEIGHT);
		this.setMinimumSize(panelDim);
		this.setPreferredSize(panelDim);
		this.setMaximumSize(panelDim);
		this.setBackground(new Color(220, 220, 220));
		this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
		// Add panel components.
		nameLabel = new JLabel();
		nameLabel.setFont(new Font("Verdana", Font.BOLD, 12));
		this.add(nameLabel);
		Font statFont = new Font("Verdana", Font.PLAIN, 10);
		scoreLabel = new JLabel();
		scoreLabel.setFont(statFont);
		;
		this.add(scoreLabel);
		moneyLabel = new JLabel();
		moneyLabel.setFont(statFont);
		this.add(moneyLabel);
		foodLabel = new JLabel();
		foodLabel.setFont(statFont);
		this.add(foodLabel);
		energyLabel = new JLabel();
		energyLabel.setFont(statFont);
		this.add(energyLabel);
		muleLabel = new JLabel();
		muleLabel.setFont(statFont);
		this.add(muleLabel);
	}

	/**
	 * Updates the player score panel with the given player's data.
	 * 
	 * @param player
	 *            The player whose data should be displayed in the panel.
	 */
	public void update(Player player) {
		nameLabel.setForeground(player.getColor());
		nameLabel.setText(player.getName());
		scoreLabel.setText("Score: " + player.getScore());
		moneyLabel.setText("Money: "
				+ player.getInventory().getAmount(Resource.MONEY));
		foodLabel.setText("Food: "
				+ player.getInventory().getAmount(Resource.FOOD));
		energyLabel.setText("Energy: "
				+ player.getInventory().getAmount(Resource.ENERGY));
		muleLabel.setText("Mule: "
				+ player.getInventory().getAmount(Resource.MULE));
	}
}
